//
//  LOLequVCViewController.m
//  LOLXXbox
//
//  Created by mac on 16/2/29.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLequVCViewController.h"
#import "LOLBasebutton.h"
#import "LOLBaseCollectionView.h"
#import "LOLequipModel.h"
#import <UIImageView+WebCache.h>
#import "LOLbigGodTableViewCell.h"
#import "LOLFitCellHeight.h"
#import "LOLFuwenViewController.h"
#import "LOLWebViewController.h"
#import "LOLDetailheroModel.h"
#define HEROHEADURL(name) [NSString stringWithFormat:@"http://img.lolbox.duowan.com/champions/%@_120x120.jpg",name]
#define WIDTH [[UIScreen mainScreen]bounds].size.width
#define HEIGHT [[UIScreen mainScreen]bounds].size.height
#define COMMENTURL(name) [NSString stringWithFormat:@"http://comment3.duowan.com/index.php?r=phone/index&domain=db.duowan.com&url=/lolcz/article/1/%@/2.html",name]



@interface LOLequVCViewController ()<UITableViewDataSource,UITableViewDelegate,GodEquipVCDelegate>
@property(nonatomic,retain)UIImageView *headImageView;
@property(nonatomic,retain)UILabel *cnNameLabel;
@property(nonatomic,retain)UILabel *priceLabel;
@property(nonatomic,retain)UILabel *propertyLabel;
@property(nonatomic,retain)LOLBasebutton *heroPKbutton;
@property(nonatomic,retain)LOLBasebutton *propertyButton;
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)LOLBaseCollectionView *cellCollectionView;
@property(nonatomic,retain)LOLequipModel *pageModel;
@property(nonatomic,retain)NSArray *typeNameArr;
@property(nonatomic,retain)NSArray *typeIntroduceArr;
@property(nonatomic,retain)NSArray *skillArr;
@property(nonatomic,retain)NSArray *pre_skillArr;
@property(nonatomic,retain)NSArray *mid_skillArr;
@property(nonatomic,retain)NSArray *end_skillArr;
@property(nonatomic,retain)NSArray *pre_equipArr;
@property(nonatomic,retain)NSArray *mid_equipArr;
@property(nonatomic,retain)NSArray *end_equipArr;
@property(nonatomic,retain)NSArray *nf_equipArr;
@end

@implementation LOLequVCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title=@"大神出装";
    
    self.pageModel = self.equipDetailBlock();
    self.typeNameArr = @[@"前期",@"中期",@"后期",@"逆风"];
    self.typeIntroduceArr = @[self.pageModel.pre_explain,self.pageModel.mid_explain,self.pageModel.end_explain,self.pageModel.nf_explain];
    self.skillArr = [self.pageModel.skill componentsSeparatedByString:@","];
    self.pre_equipArr = [self.pageModel.pre_cz componentsSeparatedByString:@","];
    self.mid_equipArr = [self.pageModel.mid_cz componentsSeparatedByString:@","];
    self.end_equipArr = [self.pageModel.end_cz componentsSeparatedByString:@","];
    self.nf_equipArr = [self.pageModel.nf_cz componentsSeparatedByString:@","];
    
    self.pre_skillArr = [NSArray arrayWithObjects:self.skillArr[0],self.skillArr[1],self.skillArr[2],self.skillArr[3],self.skillArr[4],self.skillArr[5], nil];
    self.mid_skillArr = [NSArray arrayWithObjects:self.skillArr[6],self.skillArr[7],self.skillArr[8],self.skillArr[9],self.skillArr[10],self.skillArr[11], nil];
    self.end_skillArr = [NSArray arrayWithObjects:self.skillArr[12],self.skillArr[13],self.skillArr[14],self.skillArr[15],self.skillArr[16],self.skillArr[17], nil];
    [self createBaseView];
    [self createCellTableView];

}

-(void)createBaseView {
    
    self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(8, 5, 81, 81)];
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:HEROHEADURL(self.pageModel.en_name)] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    [self.view addSubview:self.headImageView];

    
    self.cnNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(95, 10, 170, 25)];
    self.cnNameLabel.font = [UIFont systemFontOfSize:16 weight:2];
    self.cnNameLabel.text = self.pageModel.title;
    [self.view addSubview:self.cnNameLabel];

    
    
    
    self.priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(95, 40, 170, 20)];
    self.priceLabel.textColor = [UIColor grayColor];
    self.priceLabel.font = [UIFont systemFontOfSize:14];
    self.priceLabel.text = [NSString stringWithFormat:@"作者 : %@",self.pageModel.author];
    [self.view addSubview:self.priceLabel];

    
    self.propertyLabel = [[UILabel alloc]initWithFrame:CGRectMake(95, 65, 130, 20)];
    self.propertyLabel.textColor = [UIColor grayColor];
    self.propertyLabel.font = [UIFont systemFontOfSize:14];
    self.propertyLabel.text = [NSString stringWithFormat:@"战斗力 : %@",self.pageModel.combat];
    [self.view addSubview:self.propertyLabel];

    
    
    
    
    self.heroPKbutton = [LOLBasebutton baseButtonFrame:CGRectMake(WIDTH-80, 10, 60, 35) buttonType:UIButtonTypeSystem buttonTitle:@"天赋符文" buttonTitleColor:[UIColor whiteColor] buttonTag:0 buttonImage:nil];
    self.heroPKbutton.backgroundColor = [UIColor colorWithRed:0.095 green:0.735 blue:1.000 alpha:0.870];
    self.heroPKbutton.layer.cornerRadius = 8;
    [self.heroPKbutton addTarget:self action:@selector(clickPropertyButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.heroPKbutton];
    
    
    
    self.propertyButton = [LOLBasebutton baseButtonFrame:CGRectMake(WIDTH-80, 60, 60, 35) buttonType:UIButtonTypeSystem buttonTitle:@"评论" buttonTitleColor:[UIColor whiteColor] buttonTag:0 buttonImage:nil];
    self.propertyButton.backgroundColor = [UIColor colorWithRed:0.095 green:0.735 blue:1.000 alpha:0.870];
    self.propertyButton.layer.cornerRadius = 8;
    [self.propertyButton addTarget:self action:@selector(clickCommentButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.propertyButton];
    
    
    
}

-(void)createCellTableView {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 100, WIDTH, HEIGHT-64-49-100) style:UITableViewStylePlain];
    self.tableView.rowHeight = HEIGHT/3.2;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.allowsSelection = NO;
    [self.view addSubview:self.tableView];

    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuse = @"GodEquipReuse";
    LOLbigGodTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[LOLbigGodTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    
    switch (indexPath.row) {
        case 0:
            cell.skillIdArr = self.pre_skillArr;
            cell.equipIdArr = self.pre_equipArr;
            break;
        case 1:
            cell.skillIdArr = self.mid_skillArr;
            cell.equipIdArr = self.mid_equipArr;
            
            break;
            
        case 2:
            cell.skillIdArr = self.end_skillArr;
            cell.equipIdArr = self.end_equipArr;
            
            break;
            
        case 3:
            cell.skillIdArr = nil;
            cell.equipIdArr = self.nf_equipArr;
            
            break;
            
            
        default:
            break;
    }
    
    //签订push协议
    cell.delegate = self;
    
    cell.en_name = self.pageModel.en_name;
    
    cell.gameTime.text = self.typeNameArr[indexPath.row];
    cell.heroIntroduceLabel.text = self.typeIntroduceArr[indexPath.row];
    
    
    return cell;
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    switch (indexPath.row) {
        case 0:
            return [LOLFitCellHeight computeCollectionViewNumData:self.pre_equipArr.count+self.pre_skillArr.count ItemHeight:(WIDTH-35)/6+10 numOflines:6]+HEIGHT/3.2/7+[LOLFitCellHeight computeLabelString:self.typeIntroduceArr[0] FontSize:15 width:WIDTH-10]+8*2;
            break;
        case 1:
            return [LOLFitCellHeight computeCollectionViewNumData:self.mid_equipArr.count+self.mid_skillArr.count ItemHeight:(WIDTH-35)/6+10 numOflines:6]+HEIGHT/3.2/7+[LOLFitCellHeight computeLabelString:self.typeIntroduceArr[1] FontSize:15 width:WIDTH-10]+8*2;
            break;
            
        case 2:
            return [LOLFitCellHeight computeCollectionViewNumData:self.end_equipArr.count+self.end_skillArr.count ItemHeight:(WIDTH-35)/6+10 numOflines:6]+HEIGHT/3.2/7+[LOLFitCellHeight computeLabelString:self.typeIntroduceArr[2] FontSize:15 width:WIDTH-10]+8*2;
            break;
            
        case 3:
            return [LOLFitCellHeight computeCollectionViewNumData:self.nf_equipArr.count ItemHeight:(WIDTH-35)/6+10 numOflines:6]+HEIGHT/3.2/7+[LOLFitCellHeight computeLabelString:self.typeIntroduceArr[3] FontSize:15 width:WIDTH-10]+8*2;
            
            break;
            
            
        default:
            break;
    }
    
    return 5;
    
}

-(void)clickPropertyButton:(UIButton *)button {
    LOLFuwenViewController *gfVC=[[LOLFuwenViewController alloc]init];
    gfVC.enName=self.pageModel.en_name;
    [self.navigationController pushViewController:gfVC animated:YES];

    
    
}
-(void)clickCommentButton:(UIButton *)button {
    
    
    LOLWebViewController *webVC = [[LOLWebViewController alloc]init];
    webVC.url = COMMENTURL(self.pageModel.record_id);
    
    [self.navigationController pushViewController:webVC animated:YES];

    
    
    
}

//-(void)pushToDetailPage:(NSString *)typeId skillId:(NSString *)skillId {
//    
//    
//    NSArray *(^block1)() = ^(){
//        
//        return @[typeId,skillId];
//    };
//    
//    LOLDetailheroModel *(^block2)() = ^(){
//        
//        return self.detailBlock();
//        
//    };
//    YMH_BaseEquipOrSkillVC *EOSVC = [[YMH_BaseEquipOrSkillVC alloc]init];
//    EOSVC.typeIdBlock = block1;
//    EOSVC.detailModelBlock = block2;
//    [self.navigationController pushViewController:EOSVC animated:YES];
//
//    
//}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
